package com.hds.modules.app.controller;

import com.hds.modules.app.entity.MsgMainBody;
import com.hds.modules.app.service.MessageMainBodyService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 用户留言
 */
@RestController
@RequestMapping("/app/ly/mainbody")
public class MessageMainBodyController {
	Logger logger = LoggerFactory.getLogger(MessageMainBodyController.class);
	
	@Resource
	private MessageMainBodyService messageMainBodyService;
	
	/** The Constant PAGE_SIZE. */
	public static final String PAGE_SIZE ="10";
	
	/**
	 * 【mainbody.save】新增
	 */
	@RequestMapping("/save")
	public boolean save(MsgMainBody msgMainBody) {
		messageMainBodyService.save(msgMainBody);
		return true;
	}
	
	/**
	 * 【mainbody.update】修改
	 */
	@RequestMapping("/update")
	public boolean update(MsgMainBody msgMainBody) {
		messageMainBodyService.update(msgMainBody);
		return true;
	}
	
	/**
	 * 【mainbody.delete】删除
	 * 【mainbody.recover】恢复
	 */
	@RequestMapping("/{op}")
	public boolean delete(MsgMainBody msgMainBody, @PathVariable("op") String op) {
		if(op!=null){
			switch (op) {
			case "delete":
				msgMainBody.setStatus(MsgMainBody.STATUS_DELETED);
				break;
			case "recover":
				msgMainBody.setStatus(MsgMainBody.STATUS_NORMAL);
				break;
			default:
				break;
			}
		}
		messageMainBodyService.update(msgMainBody);
		return true;
	}
	
	/**
	 * 【mainbody.get】获取
	 *
	 */
	@RequestMapping("/get")
	public MsgMainBody get(Integer id) {
		MsgMainBody mr=messageMainBodyService.get(id);
		if(mr!=null)
			return mr;
		else
			return null;
	}
	
	/**
	 * 【mainbody.pagelist】 主体用户分页
	 * 
	 * @param mainBody主体
	 * @param currPage 请求页,默认第一页
	 * @param targPage 请求页,默认第一页
	 * @param pageSize 每页条数,默认10
	 * @return the 分页的用户信息
	 */
//	@RequestMapping("mainbody.pagelist")
//	public PageInfo<MsgMainBody> messagePagelist(
//			@RequestParam(required = false, defaultValue = "1") int currPage,
//			@RequestParam(required = false, defaultValue = "1") int targPage,
//			@RequestParam(required = false, defaultValue = PAGE_SIZE) int pageSize){
//		return messageMainBodyService.listByPage(currPage, targPage, pageSize);
//	}
	
	

}
